<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>{$page_title}</title>
        <link href="{lib file=jquery.ui.1.10.2/css/ui-lightness/jquery-ui-1.10.2.custom.css}" rel="stylesheet">
       <script type="text/javascript" language="javascript" src="{lib file=jquery-1.6.3.min.js}"></script>
       <script language="javascript" type="text/javascript" src="{lib file=jquery.ui.1.10.2/js/jquery-ui-1.10.2.custom.js}"></script>

        <script language="javascript" type="text/javascript" src="{lib file=jquery.plugins/jquery.validate.js}"></script>
        <script language="javascript" type="text/javascript" src="{res file=js/common.js}"></script>
        <script language="javascript" type="text/javascript" src="{res file=DatePicker/WdatePicker.js}"></script>
        <script language="javascript" type="text/javascript" src="{lib file=ajaxfileupload.js}"></script>
        <script language="javascript" type="text/javascript" src="{res file=js/jquery.funkyUI.js}"></script>
        <script language="JavaScript" type="text/javascript" src="{res file=js/lan.js}"></script>
        <link href="template/style/css/style.css" type="text/css" rel="stylesheet" />
        <script language="javascript" type="text/javascript" src="{res file=js/select.js}"></script>
        <script language="javascript" type="text/javascript" src="{res file=js/auto_textarea.js}"></script>
        <style>
            label.error {color:red;}
			.center {text-align:center;}
			tr.fabric_info_list td input{width:100%;height:100%;}
			.btn-2{margin-bottom:5px;}
			input{margin-right:5px;}
            .input-1 {line-height:18px;width:158px;}
			 .select-1 {line-height:18px;width:160px;}

        </style>
    </head>
<body>
<script type="text/javascript">
$(function() {
	$('#factory_id').change(function() {
		$('#factory_name').val($(this).children(':selected').html());
	});
	if ($('#factory_name').val() == '') {
		$('#factory_id').change();
	}
	$('select[select_input="select_input"]').each(function(i) {
		init_select_input($(this));
	});
	$('div.select-input').each(function(i) {
		$(this).css('z-index', $('div.select-input').length - i);
	});
});

function get_sample(obj){
	var id=obj.value;
	if(!id) return;
	$.getJSON('index.php?app=order&act=getsample&ajax=1&id='+id,function(json){
		if(json.done){
			$('#arrival_date').attr('value',json.retval.arrival_date);
			if(json.retval.front_pic!=''){
				$('#front_pic').attr('value',json.retval.front_pic);
				$('#front_image').attr('src',json.retval.front_pic);
				$('#front_image').show();
			}
			if(json.retval.other_pic!=''){
				$('#back_image').attr('src',json.retval.other_pic);
				$('#back_pic').attr('value',json.retval.other_pic);
				$('#back_image').show();
			}
			$('#style_id').attr('value',json.retval.style_id);
			$('#special_id').attr('value',json.retval.special_id);
			$('#factory_id').attr('value',json.retval.factory_id);
			$('#fabric_id').attr('value',json.retval.fabric_id);
			$('#feature_id').attr('value',json.retval.feature_id);
			/*$('#factory_files').html('');
			var files = json.retval.factory_files;
			for (var key in files) {
				$('#factory_files').html($('#factory_files').html() + ($('#factory_files').html() == '' ? '' : '<br />'));
				if("{$user.role}"=="{$u_client}"){
					$('#factory_files').html($('#factory_files').html()+ '<a href="download.php?id=' + files[key].file_id + '">' + files[key].file_name + '</a>');
				}else{
					$('#factory_files').html($('#factory_files').html() + '<a href="download.php?id=' + files[key].file_id + '">' + files[key].file_name + '</a><a class="pic_del" href="{url app=comupload&act=delete&id=}' + files[key].file_id + '" onClick="return confirm(\'{$lang.confirm_del_file}\')" title="{$lang.delete}">&nbsp;</a>');
				}
			}*/
		}else{
			alert(json.msg);
		}
	});
}

function get_order(obj){
	var style_sn=obj.value;
	if(!style_sn)
	{
		 return;
	}
	$.getJSON('index.php?app=order&act=getorder&ajax=1&style_sn='+style_sn,function(json){
		if(json.done){
			if(json.retval.front_pic!=''){
				$('#front_pic').attr('value',json.retval.front_pic);
				$('#front_image').attr('src',json.retval.front_pic);
				$('#front_image').show();
			}
			else
			{
				$('#front_pic').attr('value',"");
				$('#front_image').attr('src',"not_exist.jpg");
			}
			if(json.retval.back_pic!=''){
				$('#back_image').attr('src',json.retval.back_pic);
				$('#back_pic').attr('value',json.retval.back_pic);
				$('#back_image').show();
			}
			else
			{
				$('#back_image').attr('src',"not_exist.jpg");
				$('#back_pic').attr('value',"");
			}
			$('#brand_id').attr('value',json.retval.brand_id);
			$('#buyer_id option').remove();
			$('#buyer_id').append("<option value='"+json.retval.buyer_id+"'>"+json.retval.buyer_name+"</option>");
			$('#merchandiser_id option').remove();
			$('#merchandiser_id').append("<option value='"+json.retval.merchandiser_id+"'>"+json.retval.merchandiser+"</option>");
			$('#style_id').attr('value',json.retval.style_id);
			$('#factory_id').attr('value',json.retval.factory_id);
			$('#factory_price').val(json.retval.factory_price);
			$('#customer_price').val(json.retval.customer_price);
			
			$('#order_sn').val(json.retval.order_sn);
			$('#style_sn').val(json.retval.style_sn);
			$('#quantity').val(json.retval.quantity);
			$('#release_date').val(json.retval.release_date);
			$('#buyer_arrival_date').val(json.retval.buyer_arrival_date);
			$("#clone_order_id").val(json.retval.order_id);
			
		}else{
			alert(json.msg);
		}
	});
}

function change_pic(id){
	$.funkyUI({url:"index.php?app=comupload&act=order_pics&id="+id,css:{width:"400",height:"250"}});
	return false;
}

function check_create_order()
{

	var err_msg='';
	if($("#buyer_arrival_date").val()=="")
	{
		err_msg="请输入客人入仓期,客人入仓期不能为空";
	}
	if($("#quantity").val()=="")
	{
		err_msg="请输入件数,件数不能为空";
	}
	if($("#style_sn").val()=="")
	{
		err_msg="请输入款号,款号不能为空";
	}
	if($("#order_sn").val()=="")
	{
		err_msg="请输入订单号,订单号不能为空";
	}
	if($("#merchandiser_id").val()=="0")
	{
		err_msg="请选择跟单,跟单不能为空";
	}	
	if($("#buyer_id").val()=="")
	{
		err_msg="请选择买手,买手不能为空";
	}	
	/* if($("#brand_id").val()=="0")
	{
		err_msg="请选择品牌,品牌不能为空";
	} */
	
	if(err_msg!='')
	{
		alert(err_msg);
		return false;
	}
	return true;
}
</script>
<div id="fabric_shop_data" style="display:none;"><select><!--{foreach from=$fabricshop_list item=fabric_shop}--><option value="{$fabric_shop.fabric_shop_id}">{$fabric_shop.fabric_shop_name|escape}</option><!--{/foreach}--></select></div>
<div class="sub-body">
	<h3 class="title-1 tab-frame"><span>订单信息</span></h3>
    <div class="tab-frame" style="width:900px;">
		<form method="post" name="order_add_form" id="order_add_form" onsubmit="return check_create_order()">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
            	<th  align="right" width="120">下单日期：</th>
            	<td width="180"><!--{if $order.order_create_date==0}-->{$now_date}<!--{else}-->{$order.order_create_date|date}<!--{/if}--></td>
            	<th colspan="2" width="300px">正面</th>
            	<th colspan="2" width="300px">反面</th>
            </tr>
			<tr>
            	<th  align="right">品牌：</th>
            	<td>
            		<!-- {if $is_view} -->
            			<!--{foreach from=$brand_list item=brand key=k}-->
						{if $order.brand_id == $brand.brand_id}{$brand.brand_name}&nbsp;&nbsp;({$brand.company_name|escape}){/if}
						<!--{/foreach}-->
            		<!-- {else} -->
	            	<select name="info[brand_id]"  id="brand_id" onChange="brand_change(this.value);" class="select-1">
						<!--{foreach from=$brand_list item=brand key=k}-->
						<option value="{$brand.brand_id}"{if $order.brand_id == $brand.brand_id} selected{/if}>{$brand.brand_name}&nbsp;&nbsp;({$brand.company_name|escape})</option>
						<!--{/foreach}-->
				  	</select>
				  	<!-- {/if} -->
			  </td>
            	<td colspan="2" align="center" rowspan="10"><img id="front_image" width="220" height="243" src="{$order.front_pic}" alt=""></td>
            	<td colspan="2" align="center" rowspan="10"><img id="back_image" width="220" height="243" src="{$order.back_pic}" alt=""></td>
            </tr>

        	<tr>
            	<th  align="right">买手：</th>
            	<td>
            	<!-- {if $is_view} -->
           			<!--{foreach from=$buyer_list item=buyer key=k}-->
					{if $order.buyer_id == $buyer.user_id}{$buyer.user_name}{/if}
					<!--{/foreach}-->
            	<!-- {else} -->
                <select name="info[buyer_id]"  id="buyer_id" class="select-1" onchange="buyer_change(this.value)">
					<!--{foreach from=$buyer_list item=buyer key=k}-->
					<option value="{$buyer.user_id}"{if $order.buyer_id == $buyer.user_id} selected{/if}>{$buyer.user_name}</option>
					<!--{/foreach}-->
			  </select>
			  <!-- {/if} -->
              </td>
            </tr>
           
			<tr>
            	<th  align="right">跟单：</th>
            	<td>
            	<!-- {if $is_view} -->
            		<!--{foreach from=$merchandiser_list item=merchandiser key=k}-->
					{if $order.merchandiser_id == $merchandiser.user_id}{$merchandiser.user_name}{/if}
					<!--{/foreach}-->
				<!-- {else} -->
				<select name="info[merchandiser_id]"  id="merchandiser_id" class="select-1" {if $is_view}disabled="disabled"{/if}>
					<!--{foreach from=$merchandiser_list item=merchandiser key=k}-->
					<option value="{$merchandiser.user_id}"{if $order.merchandiser_id == $merchandiser.user_id} selected{/if}>{$merchandiser.user_name}</option>
					<!--{/foreach}-->
				</select>
				<!-- {/if} -->
				</td>
            </tr>
        	<tr>
            	<th  align="right">订单号：</th>
            	<!-- {if $is_view} -->
            	<td>{$order.order_sn|escape}</td>
            	<!-- {else} -->
            	<td><input type="text" class="input-1" name="info[order_sn]" id="order_sn" value="{$order.order_sn|escape}" /></td>
            	<!-- {/if} -->
            </tr>
        	<tr>
            	<th  align="right">款号：</th>
            	<!-- {if $is_view} -->
            	<td>{$order.style_sn}</td>
            	<!-- {else} -->
            	<td><input type="text" class="input-1" name="info[style_sn]" id="style_sn" value="{$order.style_sn}"  /></td>
            	<!-- {/if} -->
            </tr>
        	<tr>
            	<th  align="right">参考板号：</th>
            	<td>
            	<!-- {if $is_view} -->
            		<!--{foreach from=$sample_list item=sample key=k}-->
					{if $order.sample_id == $sample.sample_id}{$sample.sample_sn}{/if}
					<!--{/foreach}-->
            	<!-- {else} -->
            	<select name="info[sample_id]" id="sample_id" class="select-1" onchange="get_sample(this)" >
					<option value="0">{$lang.select_pls}</option>
					<!--{foreach from=$sample_list item=sample key=k}-->
					<option value="{$sample.sample_id}"{if $order.sample_id == $sample.sample_id} selected{/if}>{$sample.sample_sn}</option>
					<!--{/foreach}-->
				</select>
				<!-- {/if} -->
				</td>
            </tr>
        	<tr>
            	<th  align="right">到板日期：</th>
            	<!-- {if $is_view} -->
            	<td><!-- {if $order.arrival_date} -->{$order.arrival_date|date:Y-m-d}<!-- {/if} --></td>
            	<!-- {else} -->
            	<td><input type="text" class="input-1" name="info[arrival_date]" id="arrival_date"  value="<!-- {if $order.arrival_date} -->{$order.arrival_date|date:Y-m-d}<!-- {/if} -->" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" /></td>
            	<!-- {/if} -->
            </tr>
        	<tr>
            	<th  align="right">款式：</th>
            	<!-- {if $is_view} -->
            	<td>
            		<!--{foreach from=$style_list item=style key=k}-->
					{if $order.style_id == $style.style_id}{$style.style_name}{/if}
					<!--{/foreach}-->
				</td>
            	<!-- {else} -->
            	<td><select name="info[style_id]" id="style_id" class="select-1"   >
					<option value="0">{$lang.select_pls}</option>
					<!--{foreach from=$style_list item=style key=k}-->
					<option value="{$style.style_id}"{if $order.style_id == $style.style_id} selected{/if} >{$style.style_name}</option>
					<!--{/foreach}-->
				</select></td>
				<!-- {/if} -->
            </tr>
        	<tr>
            	<th  align="right">运输：</th>
            	<td>
            	<!-- {if $is_view} -->
            	{if $order.trans_type == 1}空运{else}海运{/if}
            	<!-- {else} -->
            	<select class="select-1" name="info[trans_type]" id="trans_type"  >
                   <option value="0">海运</option>
                   <option value="1"{if $order.trans_type == 1} selected{/if}>空运</option>
                </select>
                <!-- {/if} -->
                </td>
            </tr>
            <tr>
            	<th  align="right">目的地：</th>
            	<td>
            		<!-- {if $is_view} -->
            			<!--{foreach from=$brand_addr_name item=brand_addr key=k}-->
						{if $order.brand_addr == $brand_addr}{$brand_addr}{/if}
						<!--{/foreach}-->
            		<!-- {else} -->
            	    <select name="info[brand_addr]" id="brand_addr" class="select-1"  >
						<option value="0">{$lang.select_pls}</option>
						<!--{foreach from=$brand_addr_name item=brand_addr key=k}-->
						<option value="{$brand_addr}"{if $order.brand_addr == $brand_addr} selected{/if}>{$brand_addr}</option>
						<!--{/foreach}-->
					</select>
					<!-- {/if} -->
			   </td>
            </tr>
			<tr>
            	<th  align="right">件数：</th>
            	<!-- {if $is_view} -->
            	<td>{$order.quantity}</td>
            	<td colspan="4">&nbsp;</td>
            	<!-- {else} -->
            	<td><input type="text" class="input-1" name="info[quantity]" id="quantity" value="{$order.quantity}"   /></td>
            	<td colspan="4" style="text-align:center;"><input id="front_pic" type="hidden" name="info[front_pic]" value="{$order.front_pic}"><input id="back_pic" type="hidden" name="info[back_pic]" value="{$order.back_pic}"><input type="button"  onclick="change_pic('{$order.order_id}');" class="btn-3"   value="更新图片"></td>
            	<!-- {/if} -->
            </tr>
			<tr>
            	<th  align="right">客人价格：</th>
            	<!-- {if $is_view} -->
            	<td>{$order.customer_price|default:0}&nbsp;{$order.customer_price_name}</td>
            	<!-- {else} -->
            	<td>
            		<input type="text" size="8"  name="info[customer_price]" id="customer_price" value="{$order.customer_price}" />
                    <select name="info[customer_price_name]" id="customer_price_name" >
                    	<option {if $order.customer_price_name == '美元'} selected{/if} value="美元">美元</option>
						<option {if $order.customer_price_name == '人民币'} selected{/if} value="人民币">人民币</option>
					</select>
            	</td>
            	<!-- {/if} -->
            	<th  align="right">客人入仓日期：</th>
            	<td>
            	<!-- {if $is_view} -->
            	<!-- {if $order.buyer_arrival_date} -->{$order.buyer_arrival_date|date:Y-m-d}<!-- {/if} -->
            	<!-- {else} -->
                <input  type="text" class="input-1" name="info[buyer_arrival_date]" id="buyer_arrival_date" value="<!-- {if $order.buyer_arrival_date} -->{$order.buyer_arrival_date|date:Y-m-d}<!-- {/if} -->"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"  />
				<!-- {/if} -->
				</td>
				<th align="right">{$lang.recomm_color}：</th>
			    <td align="left">&nbsp;&nbsp;<a href="{url app=order&act=recomm_view&order_id=$order.order_id}">查看</a></td>
            </tr>
        	<!-- {if $user.role==USER_CLIENT || $user.role==USER_MERCHANDISER || $user.role==USER_MANAGER} -->
			<tr>
				<th rowspan="2" align="right">客户评语：</th>
				<td colspan="5"><textarea style="width:99%; height:50px;" id="customer_reviews" name="info[consumer_comment_text]" <!-- {if $user.role!=USER_CLIENT || ($is_view && $order.status!=ORDER_STATUS_CONFIRM)} -->readonly="readonly"<!-- {/if} -->>{$order.consumer_comment_text}</textarea>
				</td>
			</tr>
          <tr>
				<td colspan="5">
				<!-- {if $user.role==USER_CLIENT && !$is_view || $order.status==ORDER_STATUS_CONFIRM} -->
                 <input {if $is_view && $order.status!=ORDER_STATUS_CONFIRM}disabled="disabled"{/if} type="button" class="btn-3" value="{$lang.upload_enclosure}" onClick="upload_docs({$consumer_comment_order}, {$order.order_id});" />
                <!-- {/if} -->
            
           <div id="file_consumer_comment">
                <!--{foreach from=$file_comment item=file}-->
				<span><a href="download.php?id={$file.file_id}" >{$file.file_name}</a>
				<!-- {if $user.role==USER_CLIENT && !$is_view || $order.status==ORDER_STATUS_CONFIRM} -->
                <a class="pic_del" href="{url app=comupload&act=delete&id=$file.file_id}" onClick="return confirm('{$lang.confirm_del_file}')" title="{$lang.delete}">&nbsp;</a>
                <!-- {/if} -->
                </span>
				<!--{if !$smarty.foreach.last}--><!--{/if}--><!--{/foreach}-->
                </div>
</td>
			</tr>
<tr>
				<th rowspan="2" align="right">客户备注：</th>
				<td colspan="5"><textarea style="width:99%; height:50px;" id="consumer_remarks" name="info[consumer_remarks_text]" <!-- {if $user.role!=USER_CLIENT || ($is_view && $order.status!=ORDER_STATUS_CONFIRM)} -->readonly="readonly"<!-- {/if} -->>{$order.consumer_remarks_text}</textarea>
</td>
			</tr>
          <tr>
				<td colspan="5">
				<!-- {if $user.role==USER_CLIENT && !$is_view || $order.status==ORDER_STATUS_CONFIRM} -->
                 <input {if $is_view && $order.status!=ORDER_STATUS_CONFIRM}disabled="disabled"{/if} type="button" class="btn-3" value="{$lang.upload_enclosure}" onClick="upload_docs({$consumer_remarks_order}, {$order.order_id});" />
            	<!-- {/if} -->
           <div id="file_consumer_remarks">
                <!--{foreach from=$file_remarks item=file}-->
				<span><a href="download.php?id={$file.file_id}" >{$file.file_name}</a>
                <!-- {if $user.role==USER_CLIENT && !$is_view || $order.status==ORDER_STATUS_CONFIRM} -->
                <a class="pic_del" href="{url app=comupload&act=delete&id=$file.file_id}" onClick="return confirm('{$lang.confirm_del_file}')" title="{$lang.delete}">&nbsp;</a>
                <!-- {/if} -->
                </span>
				<!--{if !$smarty.foreach.last}--><!--{/if}--><!--{/foreach}-->
                </div>
</td>
			</tr>
			<!-- {/if} -->
			</tr>
		</table>
		<div style="text-align: center;margin: 10px;padding-bottom: 30px">
		  	<!-- {if !$is_view || $order.status==ORDER_STATUS_CONFIRM} -->
			<input type="submit" value="更新" id="submit" class="btn-2" />
            <!-- {/if} -->
            <input type="button" class="btn-2" value="返回" onclick="history.back();" />
		</div>
		</form>
	</div>
</div>
<script type="text/javascript">
//客户评语
var customer_reviews = document.getElementById("customer_reviews");
autoTextarea(customer_reviews);// 调用 

//客户备注
var consumer_remark = document.getElementById("consumer_remarks");
autoTextarea(consumer_remark);// 调用 
</script>
</body>
{$async_sendmail}
</html>